<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/include/taglib.jsp"%>
<html>
	<head>
		<meta charset="UTF-8">
		<title>我的账户-登录</title>
		<jsp:include page="/include/wchat/head.jsp"></jsp:include>
		<link type="text/css" rel="stylesheet" href="/v2/wchat/resrc/css/account.css">
	</head>
	<body>
		<div id="header">
			<a href="/wchatIndex.do" class="backto">返回</a>
			<div class="reg-log">
				<a href="/wchatRegisterInit.do">注册</a><a href="/wchatLoginInit.do"
					class="current">登录</a>
			</div>
		</div>
		<div id="wrap">
			<div class="login">
				<div class="link-touch">
					<ul class="items">
						<li>
							<label class="txt">
								账号
							</label>
							<input type="text" id="account" class="input"
								placeholder="手机/用户名/邮箱">
						</li>
						<li>
							<label class="txt">
								密码
							</label>
							<input type="password" id="password" class="input"
								placeholder="请输入密码" maxlength="16">
						</li>
					</ul>
					<div id="errorMsgUp" class="vtip errs none">
						请重新输入账号
					</div>
				</div>

				<div class="operate-button operate-acc">
					<a id="loginBtn" href="javascript:login();" class="btn">登录</a>
					<a href="/inputMobile4ResetPwd.do" class="btn-server">找回密码</a>
					<a href="/wchatRegisterInit.do" class="btn-server btn-reg">免费注册</a>
				</div>

				<input type="hidden" id="path" name="path" value="${afterLoginUrl}" />
				<input type="hidden" id="openid" name="openid" value="${session.openid }" />
			</div>
		</div>
		<jsp:include page="/include/wchat/footer.jsp"></jsp:include>
		
<script type="text/javascript">
function login() {
	//账号
	var $account = $('#account');
	//密码
	var $password = $('#password');
	//跳转路径
	var $path = $('#path');
	//信息提示
	var $errorMsgUp = $('#errorMsgUp');
	//信息提示
	var $errorMsgDown = $('#errorMsgDown');
	//验证码Div
	
	//检验账号
	if ($account.val() == null || $account.val() == '') {
	    $errorMsgUp.html('请输入账号').show();
    	return false;
	}
	//检验密码
	if ($password.val() == null || $password.val() == '') {
    	$errorMsgUp.html('请输入密码').show();
    	return false;
	}
	var param = {};
	param["paramMap.email"] = $("#account").val();
	param["paramMap.password"] = $("#password").val();
	param["paramMap.openid"] = $("#openid").val();
	//异步请求
	$.ajax({
		type: 'POST',
		url: environment.basePath + "/wchatLogin.do",
		data: param,
		beforeSend: function() {
            $("#loginBtn").attr("href","javascript:;").html("登录中...");
        },
		success: function(data) {
			if(data.code == 'loginFailed'){
				$errorMsgUp.html(data.msg).show();
				$("#loginBtn").attr("href","javascript:login();").html("登录");
			}else if(data.code == 'userForbidden'){
				$errorMsgUp.html(data.msg).show();
				$("#loginBtn").attr("href","javascript:login();").html("登录");
			}else if(data.code == 'userImperfect'){
				//注册未激活，跳转激活页面
				window.location.href = environment.basePath + "/wchatRegisterSec.do";
			}else{
				//登录成功，默认跳转至主页
				var url = environment.basePath + "/wchatIndex.do";
				if($path.val() != null && $path.val() != ''){
					//注意 path 是全路径
					url = $path.val();
				}
				window.location.href = decodeURIComponent(url);
			}
		}
	});
}
</script>
		
	</body>
</html>